'use strict'
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const apiRouter = require('./api/index')
const session = require('express-session')
const cookieParser = require('cookie-parser')
const guid = require('../common/guid/index')

// const http = require('http')
// const server = http.createServer()
// server.listen(3000, (req, res) => {
//   console.log('listen:127.0.0.1:3000')
// })
const app = express()
app.listen(3000, (req, res) => {
  console.log('http:127.0.0.1:3000')
})
// 解析表单post数据
app.use(bodyParser.urlencoded({
  extended: true
}))
app.use(bodyParser.json())
// session配置
app.use(session({
  secret: guid(), // 自定义加密字符 *已guid设置密钥*
  cookie: {
    maxAge: 60 * 1000 * 30 // 存活时间
  },
  resave: false, // 是否存储在物理磁盘中
  saveUninitialized: true // 是否强制没有初始化的session存储在storage中
}))
// cookie配置
app.use(cookieParser())
// 配置跨域问题
app.use(cors())
// 配置路由api
app.use('/api', apiRouter)
module.exports = app
